package com.hspedu.encap;

import java.util.Scanner;

public class Account {
    private String name;
    private double money;
    private String password;

    public Account() {

    }
    public Account(String name, double money, String password) {
        setName(name);
        setMoney(money);
        setPassword(password);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name != null && name.length() >= 2 && name.length() <= 4) {
            this.name = name;
        } else {
            this.name = "无名";
            System.out.println("用户名的长度需在 2~4 个字符之间,默认为无名");
        }
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        if(money >20){
            this.money = money;
        }else{
            System.out.println("余额必须>20,默认为0");
            this.money = 0;
        }
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if (password.length()==6){
            this.password = password;
        }else{
            this.password = "123456";
            System.out.println("密码必须为6位，已设为默认密码123456");
        }
    }

    //获取信息
    public String getInfo(){
        System.out.println("请输入密码：");
        Scanner sc = new Scanner(System.in);
        while(true){
            if(sc.next().equals(password)){
                return name + "信息如下:\n" + "姓名：" + name + " 余额：" + money +  " 密码：" + password;
            }else{
                System.out.println("密码错误请重新输入");
            }
        }
    }
}
